//==============================================================================
// SDL Tutorial 1
//==============================================================================
#ifndef _CAPP_H_
    #define _CAPP_H_

#include <SDL/SDL.h>
#include <vector>

#include "CEvent.h"
#include "CSurface.h"
#include "Obstacle.h"
#include "Character.h"
#include "Graph.h"
#include "Monitor.h"
#include "Grito.h"
#include "Nave.h"


class CApp : public CEvent {
    private:
        bool            Running;
        SDL_Surface*    Surf_BG;
        SDL_Surface*    Surf_heal;
        /// Personajes del juego
        Monitor m;
        /// El mapa del terreno
        SDL_Surface*    Surf_mapaObstaculo;
        /// Velocidad de pintado de la pantalla.
        Uint32 framesPerSecond; //Milliseconds
        Uint32 old_time;
    public:
        SDL_Surface*    Surf_Display;
        /* * * * * * * * * * * */
        // Activa/desactiva mostrar el grafo de caminos
        bool _flag_showGraph;
        bool _flag_showOlor;
        bool _flag_showSonido;
        bool _flag_showCustomSonido;

        CApp();
        int OnExecute();
        bool OnInit();
        void OnLoop();
        void OnRender();
        void OnCleanup();
        // Eventos
        void OnEvent(SDL_Event* Event);
        void OnExit();
        void OnLButtonDown(int mX, int mY);
        void OnRButtonDown(int mX, int mY);
        void OnMouseMove(int mX, int mY, int relX, int relY, bool Left,bool Right,bool Middle);
        void OnKeyDown(SDLKey sym, SDLMod mod, Uint16 unicode);
        // Funciones de uso global
        Node *findNearestNode(float point[2]);
        Graph *getGraph();
        Character* GetPlayer();
        Platform* getPlatform(float p[3]);
        Character*enemyMasCercano(Kinematic* k);
        void Yells(Kinematic *k);
        Obstacle* getCollision(Character* c,
        float **current, float **I, float **N);
        vector<Character*> getEnemyNear(Kinematic *k);
        Character* getEnemyToAttack(Kinematic *k);
        void PikmenComes(float p[3]);
        void PikmenFree();
        Character * enemyCerca(Kinematic *myK);
        void changeWind();
        bool enemyCercaB(Kinematic *myK);
        void atacar(Kinematic *myK);
        void change();
};

float fixX(float x);
float fixY(float y);

extern CApp theApp;

extern const char *f_name;
extern int TAM_VENTANA_X;
extern int TAM_VENTANA_Y;
extern int TAM_MAX_VENTANA_X; // (TAM_VENTANA_X*4)
extern int TAM_MAX_VENTANA_Y; // (TAM_VENTANA_Y*2)

extern int PSEEK;
extern int PSEEKPNOW;
extern int PWAITINGP;
extern int PRUN;
extern int PATTACK;
extern int PGO;
extern int PHEAL;
extern int PATTACKE;
extern int PRUNE;
extern int PWAITINGPE;


extern float g_player_x;
extern float g_player_y;
extern float wind_dir_x;
extern float wind_dir_y;
extern float wind_dir_time;
extern float wind_dir_oldTime;
extern Character * _flash_pikmen;
extern vector<Character*>* enemySep;
extern vector<Nave*> naves;
extern bool termino;


#endif
